/*
 * Copyright 2019 WeBank
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.webank.wedatasphere.qualitis.response;

import java.io.Serializable;

/**
 * @author howeye
 */
public class GeneralResponse<T> implements Serializable {
    private String code;
    private String message;
    private T data;

    private long count;

    public GeneralResponse() {
    }



    public GeneralResponse(String code, String message, T data, long count) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.count = count;
    }

    public GeneralResponse(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    /**
     * Description:常用返回数据抽离
     */
    public static <T> GeneralResponse<T> Ok(String msg, T data) {
        return new GeneralResponse<T>("200", msg, data);
    }

    public static <T> GeneralResponse<T> error(String errorMsg, T data) {
        return new GeneralResponse<T>("500", errorMsg, data);
    }

    public static <T> GeneralResponse<T> error(String errorMsg) {
        return new GeneralResponse<T>("500", errorMsg, null);
    }

    public static <T> GeneralResponse<T> Ok(T data) {
        return new GeneralResponse<T>("200", "Success", data);
    }

    public static <T> GeneralResponse<T> OkPage(T data,long count) {
        return new GeneralResponse<T>("0", "Success", data,count);
    }

    public static <T> GeneralResponse<T> Ok() {
        return new GeneralResponse<T>("200", "Success", null);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
